<template>
  <div class="discovery-container">
    <!-- 轮播图 -->
    <el-carousel class="" :interval="4000" type="card">
      <el-carousel-item v-for="(banner, index) in banners" :key="index" >
        <img :src="banner.imageUrl" alt="" />
      </el-carousel-item>
    </el-carousel>
    <!-- 推荐歌单 -->
    <div class="recommend">
      <h3 class="title">
        推荐歌单
      </h3>
      <div class="items">
        <div class="item" @click="toPlaylist(list.id)" v-for="(list,index) in lists" :key="index">
          <div class="img-wrap">
            <div class="desc-wrap">
              <span class="desc">{{list.copywriter}}</span>
            </div>
            <img v-lazy="list.picUrl" alt="" />
            <span class="iconfont icon-play"></span>
          </div>
          <p class="name">{{list.name}}</p>
        </div>
      </div>
    </div>
    <!-- 最新音乐 -->
    <div class="news">
      <h3 class="title">
        最新音乐
      </h3>
      <div class="items">
        <div class="item"  v-for="(newMusic, index) in newMusics" :key="index">
          <div class="img-wrap">
            <img v-lazy="newMusic.picUrl" alt="" />
            <span @click="play(newMusic.id)" class="iconfont icon-play"></span>
          </div>
          <div class="song-wrap">
            <div class="song-name">{{newMusic.name}}</div>
            <div class="singer">{{newMusic.song.artists[0].name}}</div>
          </div>
        </div>
      </div>
    </div>
    
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'discovery',
  data() {
    return {
      // 轮播图
      banners: [],
      // 推荐歌单
      lists:[],
      // 最新音乐
      newMusics:[],
      // 推荐MV
      MVs:[],
    };
  },
  methods: {
    // 点击播放
    play(id){
      axios({
        url:'https://autumnfish.cn/song/url',
        method:'get',
        params:{
          id
        }
      }).then(res=>{
        console.log(res);
        let url = res.data.data[0].url
        // 设置给父组件的播放地址
        this.$parent.musicUrl = url
      })
    },
    toMv(id){
      this.$router.push(`\mv?name=${id}`)
    },
    toPlaylist(id){
      this.$router.push(`\playlist?name=${id}`)
    }
  },
  created() {
    // 轮播图接口
    axios({
      url:'https://autumnfish.cn/banner',
      method:'get',
    }).then(res=>{
      // console.log(res);
      this.banners = res.data.banners
    }),
    // 推荐歌单
    axios({
      url:'https://autumnfish.cn/personalized',
      method:'get',
      params:{
        limit:10
      }
    }).then(res=>{
      // console.log(res);
      this.lists = res.data.result
    }),
    // 最新音乐
    axios({
      url:'https://autumnfish.cn/personalized/newsong',
      method:'get',
    }).then(res=>{
      // console.log(res);
      this.newMusics = res.data.result
    }),
    // 推荐MV
    axios({
      url:'https://autumnfish.cn/personalized/mv',
      method:'get',
    }).then(res=>{
      console.log(res);
      this.MVs = res.data.result
    })
  },
};
</script>

<style >

</style>
